package cn.emailChat.ai.replychain;

import cn.emailChat.ai.dto.MailInboundEvent;
import cn.emailChat.ai.replychain.util.DeepSeekMailHandler;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
/**
 * @Description DeepSeek 节点
 * @Author susu
 * @Date 2025/8/18
 */
@Slf4j
@Component
@Order(2)
@RequiredArgsConstructor
public class DeepSeekReplyHandler extends AbstractReplyHandler {

    private final DeepSeekMailHandler deepSeekMailHandler;

    @Override
    protected String tryHandle(MailInboundEvent e) {
        try {
            String ans = deepSeekMailHandler.answerEmail(e.getSubject(), e.getFromEmail(), e.getPlainText());
            if (ans != null && !ans.trim().isEmpty()) {
                log.info("[ReplyChain] DeepSeek 成功生成回复");
                return ans;
            }
            log.warn("[ReplyChain] DeepSeek 未得到有效回复，放行给下一节点");
        } catch (Exception ex) {
            log.error("[ReplyChain] DeepSeek 处理异常，放行给下一节点", ex);
        }
        return null;
    }
}